<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8">
        <title>点击变色演示</title>
        <style>
            div {
                width: 200px;
                height: 200px;
                margin: 10px;
                border: 1px solid #000;
            }
            .background {
                background-color: red;
            }
        </style>
    </head>
    <body>
        <div></div>
        <div></div>
        <div></div>
        <div></div>
        <div></div>
        
        <script>
            // 获取所有div元素并绑定点击事件
            const divs = document.getElementsByTagName('div');
            Array.from(divs).forEach(div => {
                div.addEventListener('click', function() {
                    this.classList.toggle('background'); // 切换红色背景类
                });
            });
        </script>
    </body>
</html>
